//
//  DeviceDetailCell.m
//  efairy
//
//  Created by 李锋 on 2019/1/16.
//  Copyright © 2019年 East. All rights reserved.
//

#import "DeviceDetailCell.h"

@implementation DeviceDetailCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        [self initView];
    }
    return self;
}

-(void)initView{
    _deviceName = [[UILabel alloc]init];// 设备名称
    _deviceName.font = [UIFont boldSystemFontOfSize:16.f];
    _deviceName.textColor = ColorFromRGB(0x333333);
    
    _deviceVersion = [[UILabel alloc]init]; // 版本号
    _deviceVersion.font = [UIFont systemFontOfSize:13.f];
    _deviceVersion.textColor = ColorFromRGB(0x666666);
    _deviceVersion.textAlignment  = NSTextAlignmentRight;
    
    _line = [[UIView alloc]init];
    _line.backgroundColor = ColorFromRGB(0xefefef);
    
    _nameTitle = [[UILabel alloc]init];//所属项目
    _nameTitle.font = [UIFont systemFontOfSize:14.f];
    _nameTitle.textColor = ColorFromRGB(0x333333);
    _nameTitle.text = @"所属项目";
    _projectName = [[UILabel alloc]init];//所属项目
    _projectName.font = [UIFont systemFontOfSize:14.f];
    _projectName.textColor = ColorFromRGB(0x999999);
    _projectName.textAlignment = NSTextAlignmentRight;
    
    
    _idTitle = [[UILabel alloc]init];//设备编号
    _idTitle.font = [UIFont systemFontOfSize:14.f];
    _idTitle.textColor = ColorFromRGB(0x333333);
    _idTitle.text = @"设备编号";
    _deviceId = [[UILabel alloc]init]; // 设备编号(设备id)
    _deviceId.font = [UIFont systemFontOfSize:14.f];
    _deviceId.textColor = ColorFromRGB(0x999999);
    _deviceId.textAlignment = NSTextAlignmentRight;
    
    _mainCodeTitle = [[UILabel alloc]init];// 设备主编吗
    _mainCodeTitle.font = [UIFont systemFontOfSize:14.f];
    _mainCodeTitle.textColor = ColorFromRGB(0x333333);
    _mainCodeTitle.text = @"设备主编码";
    _deviceMainCode = [[UILabel alloc]init];// 设备主编吗
    _deviceMainCode.font = [UIFont systemFontOfSize:14.f];
    _deviceMainCode.textColor = ColorFromRGB(0x999999);
    _deviceMainCode.textAlignment = NSTextAlignmentRight;
    
    _secondCodeTitle = [[UILabel alloc]init];//设备从编码
    _secondCodeTitle.font = [UIFont systemFontOfSize:14.f];
    _secondCodeTitle.textColor = ColorFromRGB(0x333333);
    _secondCodeTitle.text = @"设备从编码";
    _deviceSecondCode = [[UILabel alloc]init];//设备从编码
    _deviceSecondCode.font = [UIFont systemFontOfSize:14.f];
    _deviceSecondCode.textColor = ColorFromRGB(0x999999);
    _deviceSecondCode.textAlignment = NSTextAlignmentRight;
    
    _typeTitle = [[UILabel alloc]init];//设备类型
    _typeTitle.font = [UIFont systemFontOfSize:14.f];
    _typeTitle.textColor = ColorFromRGB(0x333333);
    _typeTitle.text = @"设备类型";
    _deviceType = [[UILabel alloc]init];//设备类型
    _deviceType.font = [UIFont systemFontOfSize:14.f];
    _deviceType.textColor = ColorFromRGB(0x999999);
    _deviceType.textAlignment = NSTextAlignmentRight;
    
    _installTimeTitle = [[UILabel alloc]init];//安装时间
    _installTimeTitle.font = [UIFont systemFontOfSize:14.f];
    _installTimeTitle.textColor = ColorFromRGB(0x333333);
    _installTimeTitle.text = @"安装时间";
    _deviceInstallTime = [[UILabel alloc]init];//安装时间
    _deviceInstallTime.font = [UIFont systemFontOfSize:14.f];
    _deviceInstallTime.textColor = ColorFromRGB(0x999999);
    _deviceInstallTime.textAlignment = NSTextAlignmentRight;
    
    _addressTitle = [[UILabel alloc]init];// 地址（安装位置）
    _addressTitle.font = [UIFont systemFontOfSize:14.f];
    _addressTitle.textColor = ColorFromRGB(0x333333);
    _addressTitle.text = @"安装位置";
    _deviceAddress = [[UILabel alloc]init];// 地址（安装位置）
    _deviceAddress.font = [UIFont systemFontOfSize:14.f];
    _deviceAddress.textColor = ColorFromRGB(0x999999);
    _deviceAddress.textAlignment = NSTextAlignmentRight;
    _deviceAddress.numberOfLines = 0;
    _deviceAddress.lineBreakMode = NSLineBreakByCharWrapping;
    
  
    
    
  
    
    
    [self.contentView sd_addSubviews:@[_deviceName,_deviceVersion,_line,_nameTitle,_projectName,
                                       _idTitle,_deviceId,_mainCodeTitle,_deviceMainCode,
                                       _secondCodeTitle,_deviceSecondCode,_typeTitle,_deviceType,
                                       _installTimeTitle,_deviceInstallTime,_addressTitle,_deviceAddress]];
    
    _deviceName.sd_layout.heightIs(40)
    .topSpaceToView(self.contentView,0)
    .leftSpaceToView(self.contentView, 12)
    .rightSpaceToView(self.contentView, 70);
    
    _deviceVersion.sd_layout.heightIs(40)
    .widthIs(60)
    .topSpaceToView(self.contentView,0)
    .rightSpaceToView(self.contentView, 9);
    
    _line.sd_layout.heightIs(1)
    .widthIs(SCREEN_WIDTH)
    .topSpaceToView(_deviceName,0);
    
    _nameTitle.sd_layout.heightIs(14)
    .widthIs(72)
    .topSpaceToView(_line,10)
    .leftSpaceToView(self.contentView, 12);
    
    _projectName.sd_layout.heightIs(14)
    .topSpaceToView(_line,10)
    .leftSpaceToView(_nameTitle, 6)
    .rightSpaceToView(self.contentView, 12);
    
    _idTitle.sd_layout.heightIs(14)
    .widthIs(72)
    .topSpaceToView(_projectName,10)
    .leftSpaceToView(self.contentView, 12);
    
    _deviceId.sd_layout.heightIs(14)
    .topSpaceToView(_projectName,10)
    .leftSpaceToView(_idTitle, 6)
    .rightSpaceToView(self.contentView, 12);
    
    _mainCodeTitle.sd_layout.heightIs(14)
    .widthIs(72)
    .topSpaceToView(_deviceId,10)
    .leftSpaceToView(self.contentView, 12);
    
    _deviceMainCode.sd_layout.heightIs(14)
    .topSpaceToView(_deviceId,10)
    .leftSpaceToView(_mainCodeTitle, 6)
    .rightSpaceToView(self.contentView, 12);
    
    
    _secondCodeTitle.sd_layout.heightIs(14)
    .widthIs(72)
    .topSpaceToView(_deviceMainCode,10)
    .leftSpaceToView(self.contentView, 12);
    
    _deviceSecondCode.sd_layout.heightIs(14)
    .topSpaceToView(_deviceMainCode,10)
    .leftSpaceToView(_secondCodeTitle, 6)
    .rightSpaceToView(self.contentView, 12);
    
    
    _typeTitle.sd_layout.heightIs(14)
    .widthIs(72)
    .topSpaceToView(_deviceSecondCode,10)
    .leftSpaceToView(self.contentView, 12);
    
    _deviceType.sd_layout.heightIs(14)
    .topSpaceToView(_deviceSecondCode,10)
    .leftSpaceToView(_typeTitle, 6)
    .rightSpaceToView(self.contentView, 12)
    .autoHeightRatio(0);//设置高度约束，根据内容自适应高度
    
    
    _installTimeTitle.sd_layout.heightIs(14)
    .widthIs(72)
    .topSpaceToView(_deviceType,10)
    .leftSpaceToView(self.contentView, 12);
    
    _deviceInstallTime.sd_layout.heightIs(14)
    .topSpaceToView(_deviceType,10)
    .leftSpaceToView(_installTimeTitle, 6)
    .rightSpaceToView(self.contentView, 12);
    
    _addressTitle.sd_layout.heightIs(14)
    .widthIs(72)
    .topSpaceToView(_deviceInstallTime,10)
    .leftSpaceToView(self.contentView, 12);
    
    _deviceAddress.sd_layout.heightIs(14)
    .topSpaceToView(_deviceInstallTime,10)
    .leftSpaceToView(_addressTitle, 6)
    .rightSpaceToView(self.contentView, 12)
    .autoHeightRatio(0); // 设置高度约束

    
    self.contentView.backgroundColor = [UIColor whiteColor];
    [self.contentView setupAutoHeightWithBottomView:_deviceType bottomMargin:10];
    [self setupAutoHeightWithBottomView:_deviceAddress bottomMargin:10];
    
}

-(void) setModelData:(DeviceListItem *)item{
    if(item !=nil){
        _deviceName.text = item.efairydevice_name;
        _deviceVersion.text = item.efairydevice_version;
        _projectName.text = item.efairyproject_name;
        _deviceId.text = [NSString stringWithFormat:@"%ld",item.efairydevice_id];
        _deviceMainCode.text= [item ccid];
        _deviceSecondCode.text = [item uuid_address];
        _deviceType.text =item.efairydevice_type;
        _deviceInstallTime.text = item.efairydevice_install_time;
        _deviceAddress.text = item.efairydevice_address;
        [_deviceAddress updateLayout];
    }
        
    

//    _secondCodeTitle,_deviceSecondCode,_typeTitle,_deviceType,
//    _installTimeTitle,_deviceInstallTime,_addressTitle,_deviceAddress
}

@end
